package com.mine.controller.observer;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
public class GameObservableImpl implements GameObservable{

    private boolean changed = false;
    private final List<GameObserver> observers;

    public GameObservableImpl() {
        observers = new ArrayList<>();
    }

    @Override
    public void addObserver(GameObserver observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(GameObserver observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers() {
        for(GameObserver o : observers){
            o.update(this);
        }
    }

    protected void setChanged() {
        changed = true;
    }

    protected void clearChanged() {
        changed = false;
    }
}
